<template>
	<view style="padding-top: 20upx;">
		<view class="webkit list">
			<view class="title">登录密码</view>
			<input type="text" password  @input="pwdInput" class="flex" />
		</view>
		<view class="webkit list">
			<view class="title">新密码</view>
			<input type="text" password  @input="pwd1Input" class="flex" />
		</view>
		<view class="webkit list">
			<view class="title">确认密码</view>
			<input type="text" password  @input="pwd2Input" class="flex" />
		</view>
		<view style="padding: 0 24upx;">
			<button type="primary" style="background-color: #EB2E15; margin-top: 20upx;" @click="submit" :loading="loading">确认修改</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				timestamp:'',
				codetext: '获取验证码',
				loading: false,
				codebtn: false,
				codenum: 60,
				mobile:'',
				imgcode:'',
				pwd:'',
				pwd1:'',
				pwd2:'',
				verifycode:'',
				openid:''
			};
		},
		onLoad:function(){
			// uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../login/login'
					});
				}
			});
		},
		methods:{
			setAjax(){
				uni.request({
					url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.bind&openid='+this.openid+'&app=1',
					success: res => {
						uni.hideLoading()
						// this.mobile = res.data.member.mobile
					},
					fail: () => {},
					complete: () => {}
				});
			},
			mobileInput(e) {
				this.mobile = e.target.value
			},
			imgcodeInput(e) {
				this.imgcode = e.target.value
			},
			pwd1Input(e) {
				this.pwd1 = e.target.value
			},
			pwdInput(e) {
				this.pwd = e.target.value
			},
			pwd2Input(e) {
				this.pwd2 = e.target.value
			},
			verify(e) {
				this.verifycode = e.target.value
			},
			changeImg() {
				var timestamp = (new Date()).getTime();
				this.timestamp = timestamp
			},
			getcode(){
				if (this.mobile == "") {
					uni.showToast({
						title: '请输入手机号',
						icon: "none"
					});
				} else if (this.imgcode == "") {
					uni.showToast({
						title: '请输入图形验证码',
						icon: "none"
					});
				} else {
					uni.request({
						url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=account.verifycode&app=1',
						method: 'POST',
						data: {
							mobile: this.mobile,
							temp: 'sms_bind',
							imgcode: this.imgcode
						},
						header: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						success: res => {
							uni.showToast({
								title: res.data.result.message,
								icon: "none"
							});
							if (res.data.status == 1) {
								this.codebtn = true
								var codetexts = setInterval(() => {
									this.codenum = this.codenum - 1
									this.codetext = this.codenum + 's'
								}, 1000)
								setTimeout(() => {
									this.codebtn = false
									clearInterval(codetexts);
									this.codetext = '重新发送'
								}, 60000)
							}
						},
						fail: () => {},
						complete: () => {}
					});
				}
			},
			submit(){
        let verfity = (value, names) => {
          if (!value) {
            uni.showToast({
              title: names,
              icon: 'none'
            });
            return false
          } else {
            return true
          }
        }
        if (!verfity(this.pwd, '请输入登录密码')) return false
        if (!verfity(this.pwd1, '请输入新密码')) return false
        if (!verfity(this.pwd2, '请输入确认密码')) return false
        if (this.pwd2 != this.pwd1) {
          return uni.showToast({
            title: '两次输入的密码不一致',
            icon: 'none'
          });
        }
        console.log('修改')
        
					uni.request({
						url: 'http://hszj.hongshantang696.com//app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.bind&app=1',
						method: 'POST',
						data: {
							pwd: this.pwd,
							new_pwd: this.pwd1,
							confirm: this.pwd2,
							openid:this.openid,
						},
						header: {
							'Content-Type': 'application/x-www-form-urlencoded'
						},
						success: res => {
							console.log(res)
							uni.showToast({
								title: res.data.result.message,
								icon: "none"
							});
							setTimeout(() => {
								if(res.data.status==1){
									uni.navigateTo({
										url: '../../../pages/login/login'
									});
								}
							}, 1500)
							
							
						},
						fail: () => {},
						complete: () => {}
					});
				}
			},
	}
</script>

<style>.list{padding:26upx 24upx;background:#fff;position:relative;}.list:last-child:after{display:none;}.list:after{content:" ";position:absolute;left:20upx;right:20upx;bottom:-2upx;height:2upx;border-top:2upx solid #ebebeb;color:#D9D9D9;-webkit-transform-origin:0 0;-ms-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleY(0.5);-ms-transform:scaleY(0.5);transform:scaleY(0.5);}.list .title{width:150upx;line-height:50upx;color:#666;}.list .flex{line-height:50upx;color:#666;padding-left:24upx;}.inputright{width:200upx;height:52upx;}button.inputright{line-height:48upx;font-size:24upx;background:transparent;border:2upx solid #333;}</style>